package com.abel.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.abel.web.view.LoginViewBean;

public class LoginViewValidator implements Validator {

	@SuppressWarnings("rawtypes")
	@Override
	public boolean supports(Class clazz) {
		
		return LoginViewBean.class.equals(clazz);
	}

	@Override
	public void validate(Object obj, Errors errors) {

		LoginViewBean viewBean = (LoginViewBean)obj;
		
		if (viewBean.getUserName() == null 
				|| viewBean.getUserName().equals("")) {
			errors.rejectValue("userName", "error.null",null,"User Name is required field");
		}
		//TODO - validate for special chars
		if (viewBean.getPassword() == null 
				|| viewBean.getPassword().equals("")) {
			errors.rejectValue("password", "error.null",null,"Password is required field");
		}
	}

}
